﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CROSLAND.BL.BE;
//using DECOR.DL.DALC.SAPC.Proxy;
using CroslandSAP.Proxy;
using System.Data;

namespace CROSLAND.DL.DALC.SAPC
{
    public class PersonaDALC : IPersonaDALC
    {
        
       public static PersonaDALC Instance() {
            if (_instance == null)
            {
                lock (typeof(PersonaDALC))
                {
                    if (_instance == null)
                    {
                        _instance = new PersonaDALC();
                    }
                }
            }
            return _instance;
        }

        private PersonaDALC() { }
        private static volatile PersonaDALC _instance = null;


        #region IPersonaDALC Members

        public List<PersonaBE> listarVendedores()
        {
            //PersonasProxy proxy = new PersonasProxy();
            //proxy.Connection = DALC.getConnection;
            //if (!proxy.Connection.IsOpen) { proxy.Connection.Open(); }
            //PA0001Table tblResult = new PA0001Table();

            ////proxy.Zweb_Lista_Vendedores(ref tblResult);

            //SAP.Connector.SAPConnectionPool.ReturnConnection(proxy.Connection);
            //proxy.Connection = null;
            //DataTable dt = tblResult.ToADODataTable();

            List<PersonaBE> listaResult = new List<PersonaBE>();
            //foreach (DataRow dr in dt.Rows)
            //{
            //    PersonaBE obj = new PersonaBE();
            //    obj.CodPersona = dr["PERNR"].ToString();
            //    obj.Descripcion = dr["ENAME"].ToString();
                
            //    listaResult.Add(obj);
            //}
            return listaResult;
        }

        /// <summary>
        /// Devuelve la lista de profesionales.
        /// </summary>
        /// <param name="pNombre">Nombre o parte del nombre de un profesional.</param>
        /// <returns>Devuelve lista de profesionales</returns> 
        public List<PersonaBE> listarProfesionales(string pNombre)
        {
            //PersonasProxy proxy = new PersonasProxy();
            //proxy.Connection = DALC.getConnection;
            //if (!proxy.Connection.IsOpen) { proxy.Connection.Open(); }
            //PA0001Table tblResult = new PA0001Table();

            ////proxy.Zweb_Lista_Profesionales(pNombre, ref tblResult);

            //SAP.Connector.SAPConnectionPool.ReturnConnection(proxy.Connection);
            //proxy.Connection = null;
            //DataTable dt = tblResult.ToADODataTable();

            List<PersonaBE> listaResult = new List<PersonaBE>();
            //foreach (DataRow dr in dt.Rows)
            //{
            //    PersonaBE obj = new PersonaBE();
            //    obj.CodPersona = dr["PERNR"].ToString();
            //    obj.Descripcion = dr["ENAME"].ToString();

            //    listaResult.Add(obj);
            //}
            return listaResult;
        }

        public PersonaBE leer(string pCodPersona)
        {
            //PersonasProxy proxy = new PersonasProxy();
            //proxy.Connection = DALC.getConnection;
            //if (!proxy.Connection.IsOpen) { proxy.Connection.Open(); }
            //PA0002Table tblResult = new PA0002Table();

            //proxy.Zvmc_Sd_006(pCodPersona, pCodPersona, ref tblResult);

            //SAP.Connector.SAPConnectionPool.ReturnConnection(proxy.Connection);
            //proxy.Connection = null;
            //DataTable dt = tblResult.ToADODataTable();

            PersonaBE obj = new PersonaBE();
            //if (dt.Rows.Count == 1)
            //{
            //    DataRow dr = dt.Rows[0];
            //    obj.CodPersona = dr["PERNR"].ToString();
            //    obj.Nombre = dr["VORNA"].ToString();
            //    obj.Apellido = dr["NACHN"].ToString();
            //    obj.ApeSoltero = dr["NAME2"].ToString();
            //    obj.Iniciales = dr["INITS"].ToString();
            //    obj.Descripcion = (dr["VORNA"].ToString() + " " + dr["NACHN"].ToString() + " " + dr["NAME2"].ToString()).Trim();
            //    obj.Dni = dr["RUFNM"].ToString();
            //    obj.Telefono = dr["TITEL"].ToString(); //rgutierrez 03.02.2012
            //}
            //else { return null; }
            return obj;
        }

        /// <summary>
        /// [Deprecated]
        /// </summary>
        /// <param name="pCodPersona"></param>
        /// <param name="pCodOfVtas"></param>
        /// <param name="pCodGrupoVend"></param>
        public void getInfoUsuario(string pCodPersona, out string pCodOfVtas, out string pCodGrupoVend)
        {
            //PersonasProxy proxy = new PersonasProxy();
            //proxy.Connection = DALC.getConnection;
            //if (!proxy.Connection.IsOpen) { proxy.Connection.Open(); }
            //pCodOfVtas = "";
            //pCodGrupoVend = "";
            ////proxy.Zweb_Busca_Oficina(pCodPersona, out pCodOfVtas, out pCodGrupoVend);

            //SAP.Connector.SAPConnectionPool.ReturnConnection(proxy.Connection);
            //proxy.Connection = null;
            pCodOfVtas = "";
            pCodGrupoVend = "";
        }

        #endregion
    }
}
